<template>
  <div>
    <div class="list-table">
      <div class="area-header">
        <span class="area-header-title">{{ $t('投资组合') }}</span>
      </div>
      <el-table v-loading="loading" tooltip-effect="darkTable" :data="bfInvestGroupList" border>
        <el-table-column :label="$t('公司名称')" align="center" prop="companyName" />
        <el-table-column :label="$t('行业')" align="center" prop="industryFirstLabel" width="140" />
        <el-table-column :label="$t('协议金额') + $t('金额单位')" align="center" prop="agreementAmount" width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.agreementAmount, 'w') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('划款金额') + $t('金额单位')" align="center" prop="transferAmount" width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.transferAmount, 'w') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('聚焦行业')" align="center" prop="focusIndustry" :formatter="focusIndustryFormat" width="140" />
        <el-table-column :label="$t('最新持股比例(%)')" align="center" prop="latestShareholdingRatio" width="150">
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.latestShareholdingRatio) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
          <template slot-scope="scope">
            <el-button
              v-hasPermi="['bf:investGroup:edit']"
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="updateHandle(scope.row)"
            >{{ $t('修改') }}</el-button>
            <el-button
              v-hasPermi="['bf:investGroup:remove']"
              size="small"
              type="text"
              icon="el-icon-delete"
              @click="deleteHandle(scope.row)"
            >{{ $t('删除') }}</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改参股基金_投资组合对话框 -->
      <el-dialog :title="$t('投资组合')" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
        <bfInvestGroupForm ref="bfInvestGroupForm" />
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { listBfInvestGroup, delBfInvestGroup } from '@/api/bf/investGroup/bfInvestGroup'
import bfInvestGroupForm from '@/views/bf/investGroup/bfInvestGroupForm.vue'
import { allFirstList } from '@/api/system/industry/sysIndustry'
export default {
    components: {
        bfInvestGroupForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 参股基金_投资组合表格数据
          bfInvestGroupList: [],
          // 企业阶段字典
          enterpriseStageOptions: [],
          // 企业阶段字典
          focusIndustryOptions: [],
          // 一级行业
          industryFirstOptions: [],
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              dealId: this.$route.query.id,
              pageNum: 1,
              pageSize: 2
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          },
          industryFirstLabel: ''
      }
  },
  created() {
      // 获取所有的一级行业集合
      allFirstList().then(response => {
        this.industryFirstOptions = response.data
      })
      this.getDicts('enterprise_stage').then(response => {
        this.enterpriseStageOptions = response.data
      })
      this.getDicts('deal_industry_focus').then(response => {
        this.focusIndustryOptions = response.data
      })
      this.getList()
  },
  methods: {
    /** 查询参股基金_投资组合列表 */
    getList() {
        this.loading = true
        listBfInvestGroup(this.queryParams).then(response => {
            this.bfInvestGroupList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 企业阶段字典翻译
    enterpriseStageFormat(row) {
      return this.selectDictLabel(this.enterpriseStageOptions, row.enterpriseStage)
    },
    // 聚焦行业字典翻译
    focusIndustryFormat(row) {
      return this.selectDictLabel(this.focusIndustryOptions, row.focusIndustry)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: this.$route.query.id
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.bfInvestGroupForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delBfInvestGroup(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    }
  }
}
</script>
